﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UDataBaseWork;
using XF.Meeting.Entity.DTO;

namespace XF.Common
{
    public class UserCenter
    {
        private readonly string strSqlConn = UCommonWork.Common.Commons.MD5DecodeString(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"]));
        private readonly string InitialCatalog = UCommonWork.Common.Commons.MD5DecodeString(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["InitialCatalog"]));

        public CBaseDB _db = null;


        private string obj = string.Empty;
        public UserCenter()
        {
            if (_db == null)
            {
                lock (obj)
                {
                    if (_db == null)
                    {
                        _db = new CBaseDB(strSqlConn);
                    }
                }
            }
        }
        /// <summary>
        /// 获取用户中心设置（返回数据库连接字符串）
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public string GetUserCenterSetting(out string strError)
        {
            string SqlConn = "";
           
            List<UserCenterSetting> list = new List<UserCenterSetting>();
            UserCenterSetting setting = new UserCenterSetting();
            SqlParameter[] sqlParameters = new SqlParameter[] {

                };
            CParameters parass = new CParameters();
            parass.AddRange(sqlParameters);

            if (!_db.ExcuteByTransaction(parass, "spGetUserCenterSetting", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetSettingSystem EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                list = TableToList.ToList<UserCenterSetting>(ds.Tables[0]);
                setting = list[0];
            }

            SqlConn = "Server =" + setting.DataBaseIP + "; Initial Catalog =" + InitialCatalog + "; User Id =" + setting.DataBaseAccount + "; Password =" + setting.DataBasePassword;
            return SqlConn;
        }
    }
}
